package com.hongdee.help.taskconf.service.impl;

import com.hongdee.crm.taskConfig.service.ITCrmCarTaskConfService;
import com.hongdee.help.taskconf.dao.ITaskConfDao;
import com.hongdee.help.taskconf.service.ITaskConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 关于任务分配相关处理功能
 */
@Service
public class TaskConfServiceImpl implements ITaskConfService {

    @Autowired
    private ITaskConfDao taskConfDao;
    @Autowired
    private ITCrmCarTaskConfService taskConfService;

    /**
     * 清空指定人员未开始的任务（未未完成 status=0）
     * @param saId
     * @param companyId
     */
    @Override
    public void taskRemoveNoStartBySa(String saId, String companyId) throws Exception {
        String sql="update t_crm_task_real set sa_id=null where sa_id=? and company_id=? and status='0'";
        taskConfDao.executeSQL(sql,saId,companyId);
    }

    /**
     * 空指定人员所有任务
     * @param saId
     * @param companyId
     * @throws Exception
     */
    @Override
    public void allTaskRemoveBySa(String saId, String companyId) throws Exception {
        String sql="update t_crm_task_real set sa_id=null where sa_id=? and company_id=?";
        taskConfDao.executeSQL(sql,saId,companyId);
    }

    /**
     * 清空指定公司下所有未完成的任务
     * @param companyId
     */
    @Override
    public void taskRemoveNoStatrtByCompany(String companyId) throws Exception {
        String sql="update t_crm_task_real set sa_id=null where company_id=? and status='0'";
        taskConfDao.executeSQL(sql,companyId);
    }

    /**
     * 清空指定公司下所有未任务
     * @param companyId
     */
    @Override
    public void allTaskRemoveByCompany(String companyId) throws Exception {
        String sql="update t_crm_task_real set sa_id=null where company_id=? ";
        taskConfDao.executeSQL(sql,companyId);
    }

    /**
     * 指定公司重新分配任务
     * @param companyId
     * @throws Exception
     */
    @Override
    public void taskDistByCompany(String companyId) throws Exception {
        taskConfService.distTaskByTaskConf(companyId);
    }
}
